package com.iweb.manager.controller;


import com.iweb.manager.model.User;
import com.iweb.manager.service.UserManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userManage")
public class UserManageController {
    @Autowired
    UserManageService userManageService;

    @GetMapping
    public List<User> selectAllUsers() {
        return userManageService.selectAllUsers();
    }

    @GetMapping("/{user_id}")
    public User selectOneUser(@PathVariable  int user_id) {
        return userManageService.selectOneUser(user_id);
    }

    @PutMapping
    public String updateOneUser(@ModelAttribute User user) {
        return userManageService.updateOneUser(user) == 1 ? "修改成功" : "修改失败";
    }

    @PostMapping
    public String addOneUser(@ModelAttribute User user) {
        return userManageService.addOneUser(user) == 1 ? "添加成功" : "添加失败";
    }

    @DeleteMapping
    public String deleteOneUser(@RequestParam int user_id) {
        return userManageService.deleteOneUser(user_id) == 1 ? "删除成功" : "删除失败";
    }
}
